<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      img{
       width: 500px;
       height: 500pxx;
        display: none;
      }
    </style>
  </head>
  <body>
    <button>切换</button>
    <img class="active" src="./images/1.jpg" alt="">
    <script>
      const arr = [
        "./images/1.jpg",
        "./images/2.jpg",
        "./images/3.jpg",
        "./images/4.jpg",
        "./images/5.jpg",
      ];
      let a = function() {
       return  Math.floor(Math.random()*arr.length)
      }
    console.log(a());
      const img = document.querySelector('img');
      const btn = document.querySelector('button');
      btn.addEventListener('click', function (){
        img.style.display = 'block'; 
        arr.forEach(item => {
          img.src =`${arr[a()]}`
          
        });

      });
    </script>
  </body>
</html>
